home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / dialjb / dialogjb.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-12-05  |  19.4 KB  |  537 lines

  1. VERSION 2.00
  2. Begin Form frmDialogJB 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Select Files"
  6.    ClientHeight    =   4020
  7.    ClientLeft      =   1680
  8.    ClientTop       =   1575
  9.    ClientWidth     =   7365
  10.    ClipControls    =   0   'False
  11.    FontBold        =   0   'False
  12.    FontItalic      =   0   'False
  13.    FontName        =   "MS Sans Serif"
  14.    FontSize        =   8.25
  15.    FontStrikethru  =   0   'False
  16.    FontUnderline   =   0   'False
  17.    Height          =   4425
  18.    HelpContextID   =   200
  19.    Left            =   1620
  20.    LinkTopic       =   "Form1"
  21.    MaxButton       =   0   'False
  22.    MinButton       =   0   'False
  23.    ScaleHeight     =   4020
  24.    ScaleWidth      =   7365
  25.    Top             =   1230
  26.    Width           =   7485
  27.    Begin CommandButton cmdCancelD1 'Control for Cancel button
  28.       BackColor       =   &H00C0C0C0&
  29.       Cancel          =   -1  'True--Routine cancels if ESC key is pressed
  30.       Caption         =   "&Cancel"
  31.       FontBold        =   0   'False
  32.       FontItalic      =   0   'False
  33.       FontName        =   "MS Sans Serif"
  34.       FontSize        =   8.25
  35.       FontStrikethru  =   0   'False
  36.       FontUnderline   =   0   'False
  37.       Height          =   375
  38.       HelpContextID   =   200 'I used Help Context ID's for this
  39. 'You may decide this is optional or may have other ID number
  40.       Left            =   5400
  41.       TabIndex        =   8
  42.       Top             =   720
  43.       Width           =   1095
  44.    End
  45.    Begin CommandButton cmdOKD1 'OK button, loads selected files & returns
  46. 'to main screen
  47.       BackColor       =   &H00C0C0C0&
  48.       Caption         =   "&OK"
  49.       FontBold        =   0   'False
  50.       FontItalic      =   0   'False
  51.       FontName        =   "MS Sans Serif"
  52.       FontSize        =   8.25
  53.       FontStrikethru  =   0   'False
  54.       FontUnderline   =   0   'False
  55.       Height          =   375
  56.       HelpContextID   =   200
  57.       Left            =   5400
  58.       TabIndex        =   7 'Keeping tab index order can be helpful
  59. 'for those not using a mouse
  60.       Top             =   240
  61.       Width           =   1095
  62.    End
  63.    Begin CheckBox ckSystem  'Use check box for indicating whether System
  64. 'files are read by program or not.  If your program never needs to
  65. 'read or load System files, you do not need this.
  66.       BackColor       =   &H00C0C0C0&
  67.       Caption         =   "Show System Files"
  68.       FontBold        =   0   'False
  69.       FontItalic      =   0   'False
  70.       FontName        =   "MS Sans Serif"
  71.       FontSize        =   8.25
  72.       FontStrikethru  =   0   'False
  73.       FontUnderline   =   0   'False
  74.       Height          =   375
  75.       HelpContextID   =   550
  76.       Left            =   5400
  77.       TabIndex        =   6
  78.       Top             =   2040
  79.       Width           =   1695
  80.    End
  81.    Begin CheckBox ckHidden 'Use check box for indicating whether Hidden
  82. 'files are read by program or not.  If your program never needs to
  83. 'read or load Hidden files, you do not need this.
  84.       BackColor       =   &H00C0C0C0&
  85.       Caption         =   "Show Hidden Files"
  86.       FontBold        =   0   'False
  87.       FontItalic      =   0   'False
  88.       FontName        =   "MS Sans Serif"
  89.       FontSize        =   8.25
  90.       FontStrikethru  =   0   'False
  91.       FontUnderline   =   0   'False
  92.       Height          =   375
  93.       HelpContextID   =   550
  94.       Left            =   5400
  95.       TabIndex        =   5
  96.       Top             =   1560
  97.       Width           =   1695
  98.    End
  99.    Begin DriveListBox Drive1 'Drive list box to show which drive you want
  100. 'to use. Found in nearly all file dialog boxes.
  101.       FontBold        =   0   'False
  102.       FontItalic      =   0   'False
  103.       FontName        =   "MS Sans Serif"
  104.       FontSize        =   8.25
  105.       FontStrikethru  =   0   'False
  106.       FontUnderline   =   0   'False
  107.       Height          =   315
  108.       HelpContextID   =   200
  109.       Left            =   2880
  110.       TabIndex        =   4
  111.       Top             =   3240
  112.       Width           =   2055
  113.    End
  114.    Begin DirListBox Dir1 'Directory list box to choose which directory
  115. 'you want to read or load files from
  116.       FontBold        =   0   'False
  117.       FontItalic      =   0   'False
  118.       FontName        =   "MS Sans Serif"
  119.       FontSize        =   8.25
  120.       FontStrikethru  =   0   'False
  121.       FontUnderline   =   0   'False
  122.       Height          =   1605
  123.       HelpContextID   =   200
  124.       Left            =   2880
  125.       TabIndex        =   3
  126.       Top             =   960
  127.       Width           =   2055
  128.    End
  129.    Begin FileListBox File1 'List Box for files to read or load
  130.       FontBold        =   0   'False
  131.       FontItalic      =   0   'False
  132.       FontName        =   "MS Sans Serif"
  133.       FontSize        =   8.25
  134.       FontStrikethru  =   0   'False
  135.       FontUnderline   =   0   'False
  136.       Height          =   2565
  137.       HelpContextID   =   200
  138.       Left            =   360
  139.       MultiSelect     =   2  'Extended. This can be an important switch.
  140. 'Check Visual Basic Manual for three options--choose one file only or
  141. 'two ways to select more than one file. The "Extended" mode is commonly
  142. 'used in programs which load or read more than one file at a time (like
  143. 'the Windows File Manager).
  144.       TabIndex        =   1 'Note that the Tab Index #1 should be set for
  145. 'this list box since this is the one most likely to be used.
  146.       Top             =   960
  147.       Width           =   2055
  148.    End
  149.    Begin TextBox Text1 'Use Text Box so user can enter name of file
  150. 'to load. Will also show file or first of group of files selected.
  151.       FontBold        =   0   'False
  152.       FontItalic      =   0   'False
  153.       FontName        =   "MS Sans Serif"
  154.       FontSize        =   8.25
  155.       FontStrikethru  =   0   'False
  156.       FontUnderline   =   0   'False
  157.       Height          =   285
  158.       HelpContextID   =   200
  159.       Left            =   360
  160.       TabIndex        =   0
  161.       Text            =   "*.*" 'Standard default file name in Text box
  162.       Top             =   480
  163.       Width           =   2055
  164.    End
  165.    Begin Label lblCk 'Label by Check boxes for Hidden & System files
  166. 'Not needed if your program never uses Hidden or System files
  167.       BackColor       =   &H00C0C0C0&
  168.       Caption         =   "Show Files:"
  169.       FontBold        =   0   'False
  170.       FontItalic      =   0   'False
  171.       FontName        =   "MS Sans Serif"
  172.       FontSize        =   8.25
  173.       FontStrikethru  =   0   'False
  174.       FontUnderline   =   0   'False
  175.       Height          =   255
  176.       Left            =   5400
  177.       TabIndex        =   12
  178.       Top             =   1200
  179.       Width           =   855
  180.    End
  181.    Begin Label lblDrive  'Label by Drive List Box
  182.       BackColor       =   &H00C0C0C0&
  183.       Caption         =   "Drives:"
  184.       FontBold        =   0   'False
  185.       FontItalic      =   0   'False
  186.       FontName        =   "MS Sans Serif"
  187.       FontSize        =   8.25
  188.       FontStrikethru  =   0   'False
  189.       FontUnderline   =   0   'False
  190.       Height          =   255
  191.       Left            =   2880
  192.       TabIndex        =   11
  193.       Top             =   2880
  194.       Width           =   495
  195.    End
  196.    Begin Label lblDirTop 'Label at top of Directory list box
  197.       BackColor       =   &H00C0C0C0&
  198.       Caption         =   "Directories:"
  199.       FontBold        =   0   'False
  200.       FontItalic      =   0   'False
  201.       FontName        =   "MS Sans Serif"
  202.       FontSize        =   8.25
  203.       FontStrikethru  =   0   'False
  204.       FontUnderline   =   0   'False
  205.       Height          =   255
  206.       Left            =   2880
  207.       TabIndex        =   10
  208.       Top             =   120
  209.       Width           =   855
  210.    End
  211.    Begin Label lblFile 'Label by File List Box
  212.       BackColor       =   &H00C0C0C0&
  213.       Caption         =   "File Names:"
  214.       FontBold        =   0   'False
  215.       FontItalic      =   0   'False
  216.       FontName        =   "MS Sans Serif"
  217.       FontSize        =   8.25
  218.       FontStrikethru  =   0   'False
  219.       FontUnderline   =   0   'False
  220.       Height          =   255
  221.       Left            =   360
  222.       TabIndex        =   9
  223.       Top             =   120
  224.       Width           =   855
  225.    End
  226. 'The following shapes add 3D effect to gray color of dialog box according to
  227. 'more recent Windows fashion (including Windows 95). See cover story of
  228. 'March 1995 Visual Basic Programmer's Journal.
  229.    Begin Shape rctCkW
  230.       BorderColor     =   &H00FFFFFF&
  231.       Height          =   1335
  232.       Left            =   5295
  233.       Top             =   1335
  234.       Width           =   1935
  235.    End
  236.    Begin Shape rctDriveW
  237.       BorderColor     =   &H00FFFFFF&
  238.       Height          =   735
  239.       Left            =   2775
  240.       Top             =   3015
  241.       Width           =   2295
  242.    End
  243.    Begin Shape rctDirW
  244.       BorderColor     =   &H00FFFFFF&
  245.       Height          =   2535
  246.       Left            =   2775
  247.       Top             =   255
  248.       Width           =   2295
  249.    End
  250.    Begin Shape rctFileW
  251.       BorderColor     =   &H00FFFFFF&
  252.       Height          =   3495
  253.       Left            =   255
  254.       Top             =   255
  255.       Width           =   2295
  256.    End
  257.    Begin Shape rctCkG
  258.       BorderColor     =   &H00808080&
  259.       Height          =   1335
  260.       Left            =   5280
  261.       Top             =   1320
  262.       Width           =   1935
  263.    End
  264.    Begin Shape rctDriveG
  265.       BorderColor     =   &H00808080&
  266.       Height          =   735
  267.       Left            =   2760
  268.       Top             =   3000
  269.       Width           =   2295
  270.    End
  271.    Begin Label lblDirName 'Label shows directory selected. Use label
  272. 'in conjunction with list box. Unlike Text box with file name, user
  273. 'does not enter name of directory. (User may put directory in Text box.)
  274.       BackColor       =   &H00E0E0E0&
  275.       BorderStyle     =   1  'Fixed Single
  276.       FontBold        =   0   'False
  277.       FontItalic      =   0   'False
  278.       FontName        =   "MS Sans Serif"
  279.       FontSize        =   8.25
  280.       FontStrikethru  =   0   'False
  281.       FontUnderline   =   0   'False
  282.       Height          =   255
  283.       Left            =   2880
  284.       TabIndex        =   2
  285.       Top             =   480
  286.       Width           =   2055
  287.    End
  288. 'More 3D highlighting
  289.    Begin Shape rctDirG
  290.       BackColor       =   &H00C0C0C0&
  291.       BorderColor     =   &H00808080&
  292.       Height          =   2535
  293.       Left            =   2760
  294.       Top             =   240
  295.       Width           =   2295
  296.    End
  297.    Begin Shape rctFileG
  298.       BorderColor     =   &H00808080&
  299.       Height          =   3495
  300.       Left            =   240
  301.       Top             =   240
  302.       Width           =   2295
  303.    End
  304. Option Explicit
  305. Dim DrNm$ 'Set String name for directory to read
  306. 'You may use another method of reading INI file if you
  307. 'need to.  Just change code as needed.  I found Curtis
  308. 'Smith's INIDEMO code the simplest to use without using
  309. 'any VBX's. I have found both INICON.VBX and INIDATA.VBX helpful
  310. 'VBX's, but this uses the INIDEMO code.
  311. Sub ckHidden_Click ()
  312.          'Set String for value to read from INI file.
  313.          'Set Integer (Boolean, T-F) for whether Hidden Files are read
  314. If CkHidden.Value = 1 Then 'If you click the Hidden Box on then INI file
  315. 'value is changed to reflect this
  316.      Call SetINIItem("FILENAME.INI", "APPNAME", "KEYWORD", "-1") '-1 is True
  317.      File1.Hidden = True   'Then the File box reads Hidden Files
  318.     'And INI file is changed to reflect this
  319. Else  'That is, if the Hidden box is not checked...
  320.     File1.Hidden = False  'INI value is false, and File Box skips Hidden Files
  321.     Call SetINIItem("FILENAME.INI", "APPNAME", "KEYWORD", "0")'0 is False
  322. End If
  323. End Sub
  324. Sub ckSystem_Click ()
  325.    'Set integer (Boolean, T-F) whether or System files are read
  326. If CkSystem.Value = 1 Then 'If user checks the System box...
  327.     'then INI file is changed and
  328. Call SetINIItem("FILENAME.INI", "APPNAME", "KEYWORD", "-1") '(-1 is True)
  329.      File1.System = True 'System files are read.
  330. Else 'If System check box is unchecked...
  331.     File1.System = False 'System files are not longer listed
  332.     'and INI file is changed to reflect this.
  333. Call SetINIItem("FILENAME.INI", "APPNAME", "KEYWORD", "0") '0 is False.
  334. End If
  335. End Sub
  336. Sub cmdCancelD1_Click ()
  337.     Unload frmDialogJB
  338.     frmMain.LinShadB.Visible = False 'When dialog box is unloaded,
  339. 'the shaded line which appears over the main Window to give a 3D shaded
  340. 'effect is also closed
  341. End Sub
  342. Sub cmdOKD1_Click ()
  343. 'The OK button as with standard dialog normally sends files to main program.
  344. Dim I As Integer, FN  As String 'FN is the File name, I is for the loop
  345. 'First do an error check to make sure a file has been loaded.
  346. 'If text box is either empty or has the original asterisks, nothing
  347. 'is done and nothing happens.
  348. If Text1.Text <> "*.*" And Len(Text1.Text) > 0 Then GoTo Loadfiles
  349.    Dir1_Change
  350.    Exit Sub
  351. Loadfiles:
  352. P$ = File1.Path 'Makes a simpler name for the file box path
  353. 'Check for files entered from text box but not file box
  354. Dim Selcount As Integer
  355. Selcount = 0
  356. For I = 0 To File1.ListCount - 1
  357.     If File1.Selected(I) Then
  358.         Selcount = Selcount + 1
  359.     End If
  360. Next I
  361.     If Selcount = 0 Then 'If item was manually entered into text box,
  362. 'this sends item to combo box in main program.  Clearly, you may
  363. 'choose to use a list box in your main program instead, or you may
  364. 'have some other way of loading the file, especially if you are only
  365. 'using single files.
  366.         frmMain.cboFile.AddItem Text1.Text
  367.         GoTo Morefile:
  368.     End If
  369. 'Add Selected files to frmMain.cboFile
  370. 'This adds multiple files to the combo box in your main program
  371. For I = 0 To File1.ListCount - 1
  372.     If File1.Selected(I) Then
  373.         frmMain.cboFile.AddItem File1.List(I)
  374.     End If
  375. Next I
  376. Morefile:
  377. 'This adds the path name to the main program.
  378. 'It must filter the various ways the directory and drive may be read.
  379. 'This insures that there is backslash between the directory and file name.
  380.     frmMain.cboFile.ListIndex = 0
  381.     If Right(File1.Path, 1) <> "\" Then
  382.         FN = File1.Path + "\" + frmMain.cboFile.List(0)
  383.     Else
  384.         FN = File1.Path + frmMain.cboFile.List(0)
  385.     End If
  386.     Unload frmDialogJB
  387.     frmMain.LinShadB.Visible = False  'See note by Cancel command
  388. 'Add commands as necessary for main program Window
  389. End Sub
  390. Sub Dir1_Change ()
  391. 'Handles changes user makes to directory list box
  392. If Dir1.Path <> Dir1.List(Dir1.ListIndex) Then
  393.     Dir1.Path = Dir1.List(Dir1.ListIndex)
  394. End If
  395.     DrNm$ = Dir1.Path
  396.     lblDirname = DrNm$
  397.     File1.Path = DrNm$
  398. End Sub
  399. Sub Dir1_KeyPress (KeyAscii As Integer)
  400. 'If user presses Enter while in Directory List Box, change is made
  401. If KeyAscii = 13 Then
  402.     If Dir1.Path <> Dir1.List(Dir1.ListIndex) Then
  403.         Dir1.Path = Dir1.List(Dir1.ListIndex)
  404.     End If
  405.     DrNm$ = Dir1.Path
  406.     lblDirname = DrNm$
  407.     File1.Path = DrNm$
  408. End If
  409. End Sub
  410. Sub Drive1_Change ()
  411. 'Changes drive, and checks to make sure drive is present or functioning
  412. On Error GoTo ErrCheck
  413.     Dir1.Path = Drive1.Drive
  414.     Exit Sub
  415. ErrCheck:
  416.     MsgBox "Drive Error!", 48, "MyProgram Error"
  417.     Exit Sub
  418. End Sub
  419. Sub File1_Click ()
  420. 'A single click on a file name in the file list box enters the file name
  421. 'into the text box
  422.    Text1 = File1.FileName
  423. End Sub
  424. Sub File1_DblClick ()
  425. 'A double click on a file name in the file list box enters the file name
  426. 'into the text box and loads or reads the file
  427.     Text1 = File1.FileName
  428.     cmdOKD1_Click
  429. End Sub
  430. Sub File1_KeyPress (KeyAscii As Integer)
  431. 'Pressing Enter after choosing a file in the file List box also loads
  432. 'or reads that file
  433.     If KeyAscii = 13 Then File1_DblClick
  434. End Sub
  435. Sub Form_Load ()
  436. 'When form loads, it reads from the INI file to see three things:
  437. 'The initial directory, and whether System and Hidden files are read.
  438. 'I used Curtis Smith's INIDEMO system, you may use another VBX or the Windows API
  439. 'to get the same result.  Clearly, if you don't need any of these items,
  440. 'you don't have to have this part.
  441. Dim InDir$, Sisyes%, Hidyes%, AB$, BC$
  442.     CenterForm frmDialogJB 'If you have a routine for centering the form
  443. 'then use it
  444.     frmDialogJB.Show
  445. 'Reads INI to see if System file check box is checked and System files
  446. 'Are being read.
  447. AB$ = GetINIItem$("FILENAME.INI", "APPNAME", "KEYWORD")
  448.     Sisyes% = CInt(AB$)  'Changes string to integer
  449. If Sisyes% = True Then
  450.     File1.System = True
  451.     CkSystem.Value = 1
  452.     File1.System = False
  453.     CkSystem.Value = 0
  454. End If
  455. 'Reads INI to see if Hidden File check box is checked and Hidden files
  456. 'are being read
  457. BC$ = GetINIItem$("FILENAME.INI", "APPNAME", "KEYWORD")
  458.     Hidyes% = CInt(BC$)  'Changes string to integer
  459. If Hidyes% = True Then
  460.     File1.Hidden = True
  461.     CkHidden.Value = 1
  462.     File1.Hidden = False
  463.     CkHidden.Value = 0
  464. End If
  465. 'Read INI file for Initial Directory and sets Directory and Drive list
  466. 'boxes to the appropriate drive and directory
  467.     InDir$ = GetINIItem$("FILENAME.INI", "APPNAME", "KEYWORD")
  468. Drive1.Drive = InDir$
  469. Dir1.Path = InDir$
  470. File1.Path = InDir$
  471. lblDirname = InDir$
  472. File1.FileName = ""
  473. End Sub
  474. Sub Form_Paint ()
  475. 'This adds 3D shading to Text Boxes, Outlined Labels, and List Boxes
  476.     Call BordGray3d(frmDialogJB)
  477.     Call Go3dGray(frmDialogJB, Text1)
  478.     Call Go3dGray(frmDialogJB, File1)
  479.     Call Go3dGray(frmDialogJB, lblDirname)
  480.     Call Go3dGray(frmDialogJB, Dir1)
  481.     Call Go3dGray(frmDialogJB, Drive1)
  482. End Sub
  483. 'Error filters for text entered in box so that file name is legal
  484. 'And inadvertent insertions are avoided
  485. Sub Text1_KeyDown (KeyCode As Integer, Shift As Integer)
  486.     If KeyCode = 45 And (Shift And 1) = 1 Then KeyCode = 0
  487. End Sub
  488. Sub Text1_KeyPress (KeyAscii As Integer)
  489. If KeyAscii = 13 Then GoTo Enter 'If Enter key is pressed, action continues
  490. If KeyAscii = 22 Then KeyAscii = 0
  491. If KeyAscii < Asc(" ") Then Exit Sub
  492. If KeyAscii = Asc(".") Then GoTo Period
  493. If KeyAscii > 42 And KeyAscii < 45 Then KeyAscii = 0
  494. If KeyAscii = 47 Then KeyAscii = 0
  495. If KeyAscii > 57 And KeyAscii < 64 Then KeyAscii = 0
  496. If KeyAscii > 90 And KeyAscii < 94 Then KeyAscii = 0
  497. If KeyAscii = 124 Then KeyAscii = 0
  498. Period:     'Check for more than one period
  499. Dim Periods%, Length%, I%
  500. Periods% = 0
  501. Length% = Len(Text1.Text)
  502. For I% = 1 To Length%
  503.     If Mid$(Text1.Text, I%, 1) = "." Then
  504.         Periods% = Periods% + 1
  505.     End If
  506. Next I%
  507. If Periods% >= 1 Then KeyAscii = 0
  508. 'You may need the following keys filtered also
  509. If KeyAscii >= Asc("0") Or KeyAscii <= Asc("9") Then GoTo OVR1
  510. If KeyAscii > 124 Then GoTo OVR1
  511. If KeyAscii > 35 And KeyAscii < 42 Then GoTo OVR1:
  512. If KeyAscii = 33 Then GoTo OVR1
  513. If KeyAscii > 63 And KeyAscii < 91 Then GoTo OVR1
  514. If KeyAscii > 93 And KeyAscii < 124 Then GoTo OVR1
  515. OVR1:
  516. 'Include other conditions as necessary
  517.      If Text1.SelLength = CLng(0) And KeyAscii >= 32 Then
  518.         Text1.SelLength = CLng(1)
  519.         End If
  520.    ' End If 'If other conditions
  521. Exit Sub
  522. Enter:
  523. 'Enters file or files into main program
  524. Dim FN As String
  525.     P$ = File1.Path
  526.     frmMain.cboFile.AddItem Text1.Text
  527.     frmMain.cboFile.ListIndex = 0
  528.     If Right(File1.Path, 1) <> "\" Then
  529.         FN = File1.Path + "\" + frmMain.cboFile.List(0)
  530.     Else
  531.         FN = File1.Path + frmMain.cboFile.List(0)
  532.     End If
  533. 'Add other information to main program as necessary
  534.     Unload frmDialogJB
  535.     frmMain.LinShadB.Visible = False
  536. End Sub
  537.